package com.block.channelunion.service.impl;

import cn.hutool.crypto.SecureUtil;
import com.block.channelunion.model.dto.UnionResultDTO;
import com.block.db.entity.ApplicationInfo;
import com.block.db.entity.ChannelBaseInfo;
import com.block.db.entity.ChannelUnionResultInfo;
import com.block.db.mapper.ChannelUnionResultInfoMapper;
import com.block.channelunion.service.IChannelUnionResultInfoService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.time.LocalDate;

/**
 * <p>
 * 渠道联登结果信息 服务实现类
 * </p>
 *
 * @author 
 * @since 2023-10-31
 */
@Service
public class ChannelUnionResultInfoServiceImpl extends ServiceImpl<ChannelUnionResultInfoMapper, ChannelUnionResultInfo> implements IChannelUnionResultInfoService {

    @Override
    public ChannelUnionResultInfo saveUnloginResult(String mobileMd5, ApplicationInfo applicationInfo, ChannelBaseInfo channelBaseInfo){

        ChannelUnionResultInfo unionResultInfo = new ChannelUnionResultInfo();
        unionResultInfo.setDateInfo(LocalDate.now().toString());
        unionResultInfo.setAppCode(applicationInfo.getAppCode());
        unionResultInfo.setAppName(applicationInfo.getAppName());
        unionResultInfo.setChannelCode(channelBaseInfo.getChannelCode());
        unionResultInfo.setChannelName(channelBaseInfo.getChannelName());
        unionResultInfo.setMobileMd5(SecureUtil.md5(mobileMd5).toLowerCase());
        unionResultInfo.setStatus("INIT");

        boolean save = this.save(unionResultInfo);
        if (save){
            return this.getById(unionResultInfo);
        }
        return null;
    }

    @Override
    public void updateUnionLoginResult(UnionResultDTO unionResultDTO){
        ChannelUnionResultInfo updateEntity = new ChannelUnionResultInfo();
        updateEntity.setId(unionResultDTO.getResultId());
        updateEntity.setMobile(unionResultDTO.getMobile());
        updateEntity.setStatus(unionResultDTO.getStatus());
        updateEntity.setRemarkInfo(unionResultDTO.getRemarkInfo());
        updateEntity.setUid(unionResultDTO.getUid());
        updateEntity.setUnoinLoginUrl(unionResultDTO.getUnionLoginUrl());
        boolean updateRes = this.updateById(updateEntity);

    }



}
